<template>
  <div class="websocket"></div>
</template>
<script>
import { createSocket, sendWSPush } from "@/utils/websocket";
import cache from "@/api/cache";
export default {
  name: "Websocket",
  data() {
    return {};
  },
  props: {},
  mixins: [],
  components: {},
  created() {
    this.createSocket();
  },
  mounted() {},
  updated() {},
  destroyed() {},
  computed: {},
  watch: {},
  methods: {
    createSocket() {
      let token = cache.getToken() || "";
      if (token) {
        createSocket();
        window.addEventListener("onmessageWS", this.getsocketData);
        //console.log("token", token);
        setTimeout(() => {
          sendWSPush({ type: "login", token: token, platform: "h5" });
        }, 2000);
      }
    },
    getsocketData(e) {
      console.warn("我接受到数据了e", e);
      const data = JSON.parse(e?.detail.data);
      console.warn("我接受到数据了data", data);
      console.warn("file: App.vue ~ line 71 ~ getsocketData ~ data", data);
      /* this.dataz = data.data;
      if (data.type == "theMessage" && data.data.isOpen == 1) {
        this.dialogData = data.data;
        this.params = JSON.parse(data.data.params);
        console.log(
          "file: App.vue ~ line 75 ~ getsocketData ~ this.params",
          this.params
        );
        // 	类型  1:快过期(不足两小时)、2:已过期、3:过期清除
        this.text = this.params.eType == 3 ? "前往购买" : "前往续费";
        let text = {
          1: "您有云手机剩余时长不足，届时将清空您的使用记录，是否前往续费",
          2: "您有云手机已到期，在2小时内续费可以保留您的使用记录，超出时限将清空使用记录",
          3: "您有云手机已到期，如需继续体验请前往购买",
        };
        this.content = text[this.params.eType];
        this.show = true;
        // console.log('this.dialogData', this.dialogData);
      }
      if (data.type == "otherLogin") {
        Dialog.alert({
          title: "下线通知",
          message: "您的账号在另一台手机登录,您已下线,请重新登录!",
        }).then(() => {
          // on close
          localStorage.clear();
          this.$router.push({ path: "/login" });
        });
      } */
    },
  },
};
</script>
<style lang="scss" scoped>
.websocket {
}
</style>
